<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.google.gdata.data.calendar.CalendarEntry" %>

<% request.setAttribute("tab", 2); %>
<%@ include file="/header.jsp" %>

<script><!--

function publish( ){
	var event = "<%=request.getAttribute("inserted_title")%>";
	var  me = "<%=request.getAttribute("my_uid")%>";
	var attachment = {'media':[{'type':'image','src':'http://bundundu.appspot.com/images/bundundu.JPG','href':'http://apps.facebook.com/bundundu/'}]};
	var message = 'I added an event called '+ event + ' to my google calendar using Bundundu!';
var id = Facebook.streamPublish(message, attachment, null, me);
}

function invite(){
	var selector = document.getElementById('friend_selector');
	var check = document.getElementById('check_box');
	//if(check.getChecked()==true){
		//selector.setStyle('visibility', 'visible');
//	}else{
	//	selector.setStyle('visibility', 'hidden');
	//}
	Facebook.showPermissionDialog('create_event');
}


//
--></script>

<%
		
String mensaje = ""; 
	
	if(request.getAttribute("inserted_title") != null){
		 mensaje = " <strong>" + request.getAttribute("inserted_title")
		+ "</strong> 	is now in your google calendar." 
		+ " If you want, you can add another event.";	
		 %><div id='success'><fb:success><fb:message>Yupi!</fb:message> 
		  <%= mensaje %></fb:success></div>
		  <script>
		  <!--
		  document.getElementById('success').addEventListener('onload',publish());
		  //-->
		  </script>
		  <%
	}
	else if(request.getAttribute("error") != null){
	  mensaje = " <strong>" + request.getAttribute("error")+ "</strong>";	
		 %><fb:error><fb:message>Ups!</fb:message> 
		  <%= mensaje %></fb:error><%
	}
	ArrayList<CalendarEntry> calendars = 
	  (ArrayList<CalendarEntry>)request.getAttribute("calendars");
	Integer size = (Integer)request.getAttribute("calendars_q");
	
	
%>
<div>

</div>

<div id=newEventForm>
	
	<form  name="newevent" action="<%=url%>newcalendarevent" method="post">
	<table>
		<tr>
			<td> Calendar:</td> <td>
				<select name="calendar">
				<%
					for (int i = 0; i < calendars.size(); i++) {
					  CalendarEntry entry = calendars.get(i);
					  %><option value="<%= entry.getId().toString() %>">
					   	<%=entry.getTitle().getPlainText()%>
					   </option><%
		            }
		     	%>
		     	</select>
			</td>
		</tr>
		<tr>
			<td> Title:</td> <td> 			<input type="text" name="title"/> </td>
		</tr>
		<tr>
			<td> Description:</td> <td> 	<textarea rows="5" cols="40" name="desc"/></td>
		</tr>	
		<tr>	
			<td> Where:</td> <td>			<input type="text" name="where"/> </td>
		</tr>	
		<tr>
			<td> Start date:	</td> <td>		<input type="text" name="startDate"/> (format: yyyy-mm-dd) </td>
		</tr>
		<tr>
			<td> Start hour: </td> <td><input type="text" name="startTime"/> (format: hh:mm) </td>
		</tr>
		<tr>	
			<td> End date:</td> <td>	<input type="text" name="endDate"/> (format: yyyy-mm-dd)</td>
		</tr>
		<tr>	
			<td> End hour:</td> <td> <input type="text" name="endTime"/> (format: hh:mm) </td>

		</tr>
		<tr>	
			<td colspan="2"> Create a Facebook event: <input type="checkbox" id="check_box" name="facebook_event"  onclick="invite()" value="on"/>
				<div id="friend_selector" style="visibility:hidden;">
				Invite Friends: <fb:multi-friend-input width="350px" border_color="#8496ba"  />
				</div>
			</td>
		</tr>	
</table>				
			<input type="hidden" name="is_post" value="true"/>
			<input type="submit" name="Add!" value="Add!"/><br/>
			
	
	</form>

	<br/>

	</div>
	